//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.Controls;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using HelpIcon = CommunityServer.ControlPanel.Controls.HelpIcon;
using ResourceControl = CommunityServer.ControlPanel.Controls.ResourceControl;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using StatusMessage = CommunityServer.ControlPanel.Controls.StatusMessage;

namespace CommunityServer.ControlPanel.Settings
{
	/// <summary>
	/// Summary description for SiteContent.
	/// </summary>
	public class SiteContent : BaseSettingsPage
	{

		#region Members

		protected TextBox SiteName;
		protected TextBox SiteDescription;
		protected TextBox SearchMetaDescription;
        protected TextBox GenericHeader;
		protected TextBox SearchMetaKeywords;
		protected TextBox Copyright;

		protected StatusMessage Status;
		protected ControlPanelSelectedNavigation SelectedNavigation1;
		protected ResourceControl RegionTitle;
		protected MPContent DescriptionRegion;
		protected HelpIcon Helpicon1;
		protected ResourceControl ResourceControl10;
		protected HelpIcon Helpicon2;
		protected ResourceControl ResourceControl12;
		protected HelpIcon Helpicon13;
		protected ResourceControl lblSearchMetaDescription;
		protected HelpIcon Helpicon14;
		protected ResourceControl lblSearchMetaKeyword;
		protected HelpIcon Helpicon3;
		protected ResourceControl Resourcecontrol1;
		protected HelpIcon Helpicon15;
		protected ResourceControl lblCopyright;
		protected MPContent TaskRegion;
		protected MPContainer MPContainer;
		protected ResourceLinkButton SaveButton;

		#endregion

		override protected void OnInit(EventArgs e)
		{

			this.SaveButton.Click += new EventHandler(SaveButton_Click);
			this.Load += new EventHandler(this.Page_Load);

			base.OnInit(e);
		}


		private void Page_Load(object sender, EventArgs e)
		{
			if ( !Page.IsPostBack ) 
			{
				this.Bind();
			}
		}

		protected void Bind()
		{
			SiteSettings settings = CSContext.Current.SiteSettings;
			Status.Visible = false;
			this.SaveButton.Text = ResourceManager.GetString( "Save" );

			SiteName.Text = settings.SiteName;
			SiteDescription.Text = settings.SiteDescription;
			SearchMetaDescription.Text = Transforms.StripHtmlXmlTags(settings.SearchMetaDescription);
			SearchMetaKeywords.Text = Transforms.StripHtmlXmlTags(settings.SearchMetaKeywords);
			Copyright.Text = settings.Copyright;
            GenericHeader.Text = settings.RawAdditionalHeader;

		}

		private void SaveButton_Click(object sender, EventArgs e) 
		{
			SiteSettings settings = CSContext.Current.SiteSettings;

			SaveSettings( settings );

			if(Page.IsValid)
			{
				Status.Success = true;
				Status.ResourceName = "Admin_SiteSettings_StatusSuccess";

				DataBind();
			}
			else
			{
				Status.Success = false;
				Status.ResourceName = "Admin_SiteSettings_StatusFailed";
			}

			Status.Visible = true;
		}

		private void InitializeComponent()
		{
		
		}


		protected virtual void SaveSettings( SiteSettings settings ) 
		{

			settings.SiteName = SiteName.Text;
			settings.SiteDescription = SiteDescription.Text;
			settings.SearchMetaDescription = this.SearchMetaDescription.Text;
			settings.SearchMetaKeywords = this.SearchMetaKeywords.Text;
			settings.Copyright = this.Copyright.Text;
            settings.RawAdditionalHeader = this.GenericHeader.Text;

			if(Page.IsValid)
				SiteSettingsManager.Save(settings);

		}


	}
}
